package com.pagepub.core.tag.validator;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

public class ValidateWebsite extends FormValidateBasic {
	/**
	 * @param args
	 */
	private String rightimage;
	private String rightwordcolor;
	private String submitvalidate;
	public String getSubmitvalidate() {
		return submitvalidate;
	}
	public void setSubmitvalidate(String submitvalidate) {
		this.submitvalidate = submitvalidate;
	}
	public String getRightimage() {
		return rightimage;
	}
	public void setRightimage(String rightimage) {
		this.rightimage = rightimage;
	}
	public String getRightwordcolor() {
		return rightwordcolor;
	}
	public void setRightwordcolor(String rightwordcolor) {
		this.rightwordcolor = rightwordcolor;
	}
	public int doStartTag() throws JspException {
		JspWriter out = (JspWriter) this.pageContext.getOut();   
		

		try {
			 out.print(validatewebsite());
//			 
//			System.out.println(str);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return 1;
	}
	public static void main(String[] args) {
		// TODO 自动生成方法存根

	}
	public StringBuffer validatewebsiteformat(){
		StringBuffer str=new StringBuffer();
		str.append("<script language=\"javascript\">");
		str.append("function validatewebsiteformate(realvalue,spanname,realname){");
		str.append("var flag=0;");
		str.append(" var reg=/^http:\\/\\/[A-Za-z0-9]+\\.[A-Za-z0-9]+[\\/=\\?%\\-&_~`@[\\]\\':+!]*([^<>\\\"\\\"])*$/;");
		str.append("if(realvalue!=\"\"){");
		str.append(" if (reg.test(realvalue)==false)");
		str.append("			{");
		str.append("				message=\"对不起,\"+realname+\"不合法!\";	");	
		str.append("				imgurl=\"<img src=\\\""+wrongimage+"\\\"/>\";");
		str.append(this.display());
		str.append("return false;");				
		str.append("			}");
		str.append("else {");
		str.append(this.displayempty());
		str.append("return true;}");

		str.append("		}");
		str.append("}");
		str.append("</script>");
		return str;
	}
	public StringBuffer returnfunction(){
		StringBuffer str=new StringBuffer();
	    ValidateLength  validatelength=new ValidateLength();
		validatelength.setWordcolor(wordcolor);
		validatelength.setWrongimage(wrongimage);
		str.append(validatelength.validatelength());
		DisplayRightMessage displayrightmessage=new DisplayRightMessage();
		displayrightmessage.setWordcolor(wordcolor);
		displayrightmessage.setWrongimage(wrongimage);
		displayrightmessage.setRightimage(rightimage);
		displayrightmessage.setWordcolor(this.rightwordcolor);
		str.append(displayrightmessage.displaymessage());
		return str;
	}
	public StringBuffer validatewebsite(){
		StringBuffer str=new StringBuffer();
		String emptyelement="";
	     String pluselement="";	
     
 	   
 	      if(this.submitvalidate.equalsIgnoreCase("true")){
 				emptyelement="emptyelement(realname);";
 				pluselement="else pluselement(realname);";
 			}
 	   str.append(returnfunction());
 	   str.append("<script language=\"javascript\">");
 	   str.append("function  validatewebsite(realvalue,min,max,spanname,realname) {");
 	   str.append("if(realvalue!=\"\") ");
 	   this.displayempty();
// 	   if(this.submitvalidate.equalsIgnoreCase("true")){		   
// 			str.append("dilivery(nextelementname);");
// 		}
// 	   str.append("}");
 	  str.append("if(validatewebsiteformate(realvalue,spanname,realname))");
 	   str.append("if(ValidateLength(realvalue,min,max,realname,spanname)) {" );
 	   str.append("	displayrightmessage(realvalue,spanname,realname);");
 	   str.append(emptyelement);
// 	   if(this.submitvalidate.equalsIgnoreCase("true")){
// 			str.append("dilivery(nextelementname);");
// 		}
 	   str.append("}");	
 	   str.append(pluselement);
 	  str.append(pluselement);
 	   str.append("}");
 	   
 	   str.append("</script>");
 	   str.append(this.returnfunction());
 	   str.append(this.validatewebsiteformat());
 	   return str;
		
	}
}
